Skip to content

添加了餘額查詢api的版本 - #1

Open
2357111317192329 wants to merge 2006 commits into
Hebaiju:mainfrom
2357111317192329:combined
Open

2357111317192329 wants to merge 2006 commits into
Hebaiju:mainfrom
2357111317192329:combined

Conversation

@2357111317192329

Copy link
Copy Markdown

添加了餘額查詢api,codex寫的,零測試。
使用方式見README_CN.md (其實我也不太確定我的理解是否正確,得測試看看才知道),會返回一個json。

Wei-Shaw and others added 30 commits October 2, 2026 19:52
…ted-key

fix(billing): settle usage when the API key is deleted before billing completes
…am-billing-probe

fix(billing): allow upstream billing probe for TypeSafe API-key accounts
The embedded frontend middleware runs before the gateway routes and only
let a few root aliases through. Bare aliases such as /chat/completions,
/embeddings, /messages/count_tokens and /models/:model were answered with
index.html and HTTP 200 instead of reaching the API handlers.

Add every root alias registered in routes/gateway.go to the bypass list.
This also covers POST /videos, which the /videos/ prefix did not match.

Fixes Wei-Shaw#7670
- 规则新增 scope 字段:account 命中后暂停整个账号,model 只冷却本次请求的模型;
  字段缺省时保持现有语义(模型已知且非 401 走模型级,否则账号级),显式取值由运营人员决定,401 也不例外
- 模型未知的路径按账号级兜底;状态 JSON 记录 scope/model 便于排查
- 创建/编辑账号弹窗的规则编辑器新增作用范围单选卡片,新规则默认模型级;
  未设置 scope 的存量规则按后端缺省语义回显(401 账号级、其余模型级),打开再保存不改变行为
- 后端:scope 解析归一化、缺省/显式账号级/显式模型级/模型未知兜底的分流判定,
  以及显式账号级、显式模型级 401、模型未知三种命中的落库位置与状态 JSON
- 前端:未设置 scope 的存量规则按 401 账号级、其余模型级回显并原样保存,
  显式 scope 回显与切换后提交,新增规则默认模型级
Anthropic processes cache breakpoints in tools, system, messages order and
rejects a ttl=1h breakpoint after a 5m one. The OAuth mimic path adds 5m
breakpoints to the injected system block and the last tool, so a third-party
client that marks a single message block with ttl=1h received a 400.

After the block limit, raise ephemeral breakpoints that precede the last 1h
breakpoint to 1h. Valid requests are unchanged.
AnthropicContentBlock / antigravity ClaudeContentItem serialized `signature`
with omitempty, so thinking blocks without an upstream signature (Chat
Completions reasoning_content, Responses reasoning without encrypted_content,
every streamed thinking content_block_start) went out with no `signature` key.

Anthropic always sends the key (`""` on content_block_start). Strict clients
such as Grok Build deserialize it as a required field and abort the response
or SSE stream with "missing field `signature`".

- apicompat: thinking MarshalJSON always emits `thinking` and `signature`
- antigravity: ClaudeContentItem MarshalJSON does the same; streamed thinking
  content_block_start carries `signature: ""`
- tests: wire-shape regression tests; update TestStreamingReasoning expectation

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The zhipu adapter always appended the official /api/paas/v4/chat/completions
path, so probes broke whenever the endpoint was not the official root:

- OpenAI-compatible relay (e.g. https://relay.example.com): requested
  /api/paas/v4/chat/completions, which relays do not serve -> 404
- Coding Plan base (https://open.bigmodel.cn/api/coding/paas/v4): produced
  .../coding/paas/v4/api/paas/v4/chat/completions -> 404

Resolve the path from the endpoint instead: append /chat/completions when it
already carries /paas/v4, keep the official path for bigmodel.cn / z.ai
roots, and fall back to /v1/chat/completions (same as kimi/deepseek/minimax)
for everything else.

Fixes Wei-Shaw#7067

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
An order-creation signature (visible to the payer in popup submit.php
URLs) could be replayed as a payment-success notification, with no
merchant key required. Two compounding defects:

- CanonicalizeReturnURL kept client-supplied query parameters, so a
  return_url ending in '&trade_status=TRADE_SUCCESS' entered the signed
  order string verbatim;
- the sign base string concatenates values unescaped, so a callback that
  decodes return_url only up to the smuggled pair re-sorts to a
  byte-identical sign base and passes verification.

Fixes:

- CanonicalizeReturnURL now drops client query parameters entirely; the
  server builds its own signed set and the client query has no
  legitimate use;
- VerifyNotification rejects any parameter outside the genuine async
  notify set (pid/trade_no/out_trade_no/type/name/money/trade_status/
  param/sign/sign_type), failing closed against the whole smuggling
  class regardless of the injection point.

Regression tests cover the PoC payload, full order-URL replay, genuine
callback acceptance, unknown-parameter rejection (including empty
values), and the return_url smuggling strip. Genuinely paid orders that
an exotic upstream variant might reject are still recovered through the
existing upstream QueryOrder reconcile path.
Wei-Shaw and others added 30 commits October 15, 2026 15:37
…n-support

Resolve Gemini 4 Argon pricing conflicts in favor of main (Wei-Shaw#8078), which
already provides the base and Cyber Permissive price cards, thinking-tier
pricing aliases, and the local pricing snapshot.
…5 tier IDs at base rates

- Restore runtime default passthroughs and Gemini 3.1 Pro aliases for
  explicit Antigravity model_mapping. Mappings saved before the Gemini
  3.x Flash / 3.1 Pro releases still depend on them; dropping them would
  silently remove those models from existing accounts on upgrade.
- Capability sync now skips injected-only passthrough targets, so models
  the upstream catalog omits no longer mark the sync as partial.
- Price Antigravity claude-{opus,sonnet}-5-5-{high,medium,low} at the base
  Opus/Sonnet 5.5 card instead of substring-matching claude-opus-5 /
  claude-sonnet-4-5 (1.25x-3x overbilling).
…upport

feat(antigravity): support Gemini 4 Argon and accurate upstream model catalogs
- chat/messages 兼容入口把 reasoning_effort、thinking、output_config.effort
  映射为 Gemini thinkingConfig:2.5 用 thinkingBudget,3 及以上用 thinkingLevel;
  minimal 只发给 flash 系列,medium 只发给 flash 系列与 3.1 Pro,其余升为 high;
  图像/语音/向量与无法识别版本的型号、带档位后缀的型号不写档位
- 流式请求开启 includeThoughts(messages 需客户端开启 thinking),thought part
  转为 Anthropic thinking 块,chat 侧输出为 reasoning_content
- 历史中的 thinking 块与 chat 回传的推理内容不再发给 Gemini;签名降级重试先删
  历史思考块再降级,思考参数沿用客户端原始请求
- messages 兼容路径记录实际转发的思考档位,与 chat 兼容路径一致
…rable-min-output

feat(apicompat): configure minimum output token floor
…c-base-url

fix(gateway): honor Anthropic protocol base URLs.
…e-aware-import

fix(openai): isolate Codex imports by workspace
Revert 679a718 ("feat(accounts): compact account search and filters"),
which moved the type / privacy / group filters behind a collapsed
"More filters" panel on /admin/accounts.

Polish on top of the revert:
- Widen the privacy select (w-48) so "全部Privacy状态" / "All Privacy States"
  no longer truncates.
- Narrow the search input to w-52 so all six controls fit on one row at 1440px.
- Below sm, lay the filters out as a two-column grid that fills the width
  instead of fixed-width selects with a ragged edge.
…filters

revert(accounts): restore inline account filters (Wei-Shaw#7853)
…ending

- Validate order_type (balance/subscription) at order creation and in
  fulfillment; other values are rejected with INVALID_ORDER_TYPE.
- Keep the balance/subscription deduction while a gateway refund is
  pending. The deduction is recorded in the REFUND_PENDING audit (written
  in the same transaction as the status change), not applied again on
  successful finalization, and returned once if the gateway reports
  failure. Legacy pending audits keep the previous behaviour.
- REFUND_PENDING orders are finalized via refund query only;
  PrepareRefund/ExecuteRefund no longer accept them.
- Invalidate the billing balance cache after refund deductions/returns.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The /payment/stripe route no longer carries client_secret in its query.
The page reads it from the recovery snapshot written when the order was
created and requires the snapshot order to match order_id, consistent
with AirwallexPaymentView.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
- Claim REFUND_PENDING -> REFUND_FAILED, return the held deduction and
  write the audit in one transaction. If the deduction cannot be
  returned, the order is still marked failed together with a
  REFUND_ROLLBACK_FAILED audit so a retried refund skips the deduction.
- Return an error when the REFUND_PENDING audit cannot be loaded or
  parsed instead of falling back to the legacy finalization path.
…types

- Alipay: record the generated out_request_no as the refund ID and
  implement QueryRefund (alipay.trade.fastpay.refund.query), so refunds
  that return fund_change=N can be finalized from the admin refund query.
  Refunds recorded before this change return REFUND_QUERY_UNSUPPORTED.
- Fulfillment: mark paid orders with an unsupported order type as FAILED
  with an audit entry instead of erroring, so payment callbacks are
  acknowledged; RetryFulfillment rejects them with INVALID_ORDER_TYPE.
…ot-found failure

- The SDK returns signed business-failure responses (for example
  ACQ.SYSTEM_ERROR) with a nil error and empty fields. QueryRefund now
  checks the response code and returns an error, so the order stays
  REFUND_PENDING instead of being read as "no refund record" and failed.
- A missing refund record is treated as failed only after a 10 minute
  grace period from when the refund became pending. Alipay notes that a
  query sent too soon can miss a refund that later succeeds. The pending
  time comes from the REFUND_PENDING audit entry.
…-refund-hold

fix(payment): validate order types, keep refund deductions while pending, load Stripe secret from local snapshot
…ore crediting

Order query:
- 彩虹易支付 and ZPay read act=order parameters from the URL query only;
  a body-only request is answered with "No Act!", so order status queries
  (reconcile, payment status checks) never reached the order. Parameters
  are now sent in the URL query and mirrored in the form body for forks
  that read the body.
- Decode status/money/trade_no leniently: PHP deployments commonly return
  integers as strings ("status":"1"), which previously failed the whole
  response decode. JSON null falls back to the nested data object.
- Treat a non-success code as a query error instead of an unpaid order,
  and require an echoed out_trade_no to match the queried order.
- Strip the request URL (which carries the merchant key) from transport
  errors before they are returned.

Notifications:
- Add payment.NotificationConfirmer. After a notification is verified, the
  webhook asks the same provider instance to confirm it; EasyPay queries
  the upstream order and requires it to be paid with a matching amount and
  trade_no (a missing notify trade_no is filled from the query). Failures
  are recorded as PAYMENT_UPSTREAM_UNCONFIRMED and answered with 502 so the
  gateway retries; the order stays pending and reconcile still applies.
- EasyPay notifications must carry the instance's configured pid, and
  field values other than name must be plain tokens.
- Return URLs must use a plain hostname or IP literal without userinfo.
fix(payment): fix EasyPay order queries and confirm notifications before crediting
# Conflicts:
#	backend/internal/service/gemini_chat_completions_compat_service.go
feat(gemini): 兼容入口转发思考档位并流式返回思考摘要
grok-build / Codex 等 Rust serde 客户端把 Response.created_at 与事件的
sequence_number 当必填字段,缺失即 `missing field 'created_at'` 整轮读不出响应。
Wei-Shaw#5601 只补了 apicompat 两座桥的合成路径,以下出口仍会送出缺字段的对象:

- 合成的 response.failed:buildOpenAIResponseFailedSSE(主流 + 透传)与
  buildOpenAIWSHTTPBridgeFailedEvent 在流以裸 error 结束时补发终止帧,
  缺 created_at,前者还缺 sequence_number。现统一写出:created_at 取本流
  上游值(无则当前时间),sequence_number 沿用被替换的裸 error 帧序号(无则 0)。
- 上游原样透出:Grok 账号挂第三方中转时,上游 Response 对象可能不带
  created_at,网关逐字节转发后客户端同样失败。现于 Responses 流式出口、
  WS HTTP 桥(Grok WS 恒走此路)与非流式 JSON 出口,对缺失/null 的
  created_at 补一个整条流固定的时间戳;上游已带时输出逐字节不变。

透传路径保持不改写上游事件,只观察 created_at 供合成终止帧对齐。

Fixes Wei-Shaw#8118
网关现会为缺 created_at 的 Response 对象补齐该字段(Wei-Shaw#8118),该测试以
"输出包含上游原始字节"断言模型改写,夹具缺 created_at 时输出多出补齐字段
而失配。夹具改为真实上游必带 created_at 的形态,测试意图(仅改写 model)不变。
网关现会为缺 created_at 的 Response 对象补齐该字段(Wei-Shaw#8118),该测试以
"输出包含上游原始字节"断言模型改写,夹具缺 created_at 时输出多出补齐字段
而失配。夹具改为真实上游必带 created_at 的形态,测试意图(仅改写 model)不变。
…on-retirement

fix(openai): respect GPT-5.5 retirement on ChatGPT upstreams
…es-web-search-emulation

fix(openai): emulate web_search on /v1/messages for OpenAI API key accounts
…es-created-at

fix(responses): 网关送出的 Responses 对象一律带 created_at,修复 grok-build 反序列化失败
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.